home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / bildschirmschoner / beyondthedark / developer / source / galaxy / galaxy.c next >
C/C++ Source or Header  |  1996-04-07  |  15KB  |  499 lines

  1. /* *2Pi/360 */
  2. #include <exec/memory.h>
  3. #include <exec/execbase.h>
  4. #include <graphics/gfxbase.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <dos/dosextens.h>
  7. #include <libraries/iffparse.h>
  8. #include <utility/tagitem.h>
  9. #include <time.h>
  10. #include <limits.h>
  11.  
  12. #define __USE_SYSBASE 42
  13.  
  14. #include <proto/dos.h>
  15. #include <proto/exec.h>
  16. #include <proto/graphics.h>
  17. #include <proto/intuition.h>
  18. #include <proto/utility.h>
  19.  
  20. #include <string.h>
  21. #include <math.h>
  22. #include <m68881.h>
  23.  
  24. #include "BTD.h"
  25.  
  26. struct IntuitionBase *IntuitionBase;
  27. struct GfxBase *GfxBase;
  28. struct DosLibrary *DOSBase;
  29. struct Library *UtilityBase,*MathIeeeDoubBasBase,*MathIeeeDoubTransBase;
  30.  
  31. // #define DEBUG YES 
  32.  
  33. #ifdef DEBUG 
  34.  
  35. void KPrintF(char *,...);
  36.  
  37. #define DEBUG_PRINTF(a,b)  KPrintF(a,b);
  38. #define DEBUG_PRINT(a)     KPrintF(a)
  39. #else
  40. #define DEBUG_PRINTF(a,b)
  41. #define DEBUG_PRINT(a)
  42. #endif
  43.  
  44. #define GATAG(o) (BTD_Client+(o))
  45.  
  46. #define GA_Seconds GATAG(0)
  47. #define GA_Galaxy  GATAG(1)
  48. #define GA_Stars   GATAG(2)
  49. #define GA_Deltat  GATAG(3)
  50.  
  51. #define DEF_SECONDS 100
  52. #define DEF_GALAXY  2
  53. #define DEF_STARS   100
  54. #define DEF_DELTAT  100
  55.  
  56. #define MIN_SECONDS 1
  57. #define MIN_GALAXY  1
  58. #define MIN_STARS   10
  59. #define MIN_DELTAT  10
  60.  
  61. #define MAX_SECONDS 3600
  62. #define MAX_GALAXY  5
  63. #define MAX_STARS   1000
  64. #define MAX_DELTAT  500
  65.  
  66. struct BTDInteger GalaxyIntParams[] =
  67.  {
  68.   GA_Seconds,"Big Bang",BTDPT_INTEGER,DEF_SECONDS,MIN_SECONDS,MAX_SECONDS,TRUE,
  69.   GA_Galaxy ,"Galaxies",BTDPT_INTEGER,DEF_GALAXY,MIN_GALAXY,MAX_GALAXY,TRUE,
  70.   GA_Stars,"Stars per Galaxy",BTDPT_INTEGER,DEF_STARS,MIN_STARS,MAX_STARS,TRUE,
  71.   GA_Deltat,"Zoom",BTDPT_INTEGER,DEF_DELTAT,MIN_DELTAT,MAX_DELTAT,TRUE
  72.  } 
  73. ;
  74.  
  75. struct BTDNode *GalaxyParams[] =
  76.  {
  77.   &GalaxyIntParams[0].BI_Node,
  78.   &GalaxyIntParams[1].BI_Node,
  79.   &GalaxyIntParams[2].BI_Node,
  80.   &GalaxyIntParams[3].BI_Node,
  81.   NULL
  82.  };
  83.  
  84. struct BTDInfo GalaxyInfo =
  85.  {
  86.   BTDI_Revision,MAKE_ID('G','A','L','X'),
  87.   "Galaxia","Galaxy blanker, spinning and colliding Galaxies\nbased on an EGS Blanker from Uli Siegmund","Markus Illenseer",
  88.   GalaxyParams
  89.  };
  90.  
  91. char MyBlankerName[] = "galaxy.btd";
  92. char MyBlankerID[]   = "Spinning Galaxy V" VERSION "." REVISION " for BTD";
  93.  
  94. LONG MyBlankerLibInit(void)
  95. {
  96.  if (GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37L))
  97.   {
  98.    if (IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37L))
  99.     {
  100.      if (UtilityBase=OpenLibrary("utility.library",37L))
  101.       {
  102.        if (MathIeeeDoubBasBase=OpenLibrary("mathieeedoubbas.library",37L))
  103.         {
  104.          if (MathIeeeDoubTransBase=OpenLibrary("mathieeedoubtrans.library",37L)) return TRUE;
  105.  
  106.          CloseLibrary (MathIeeeDoubBasBase);
  107.         }
  108.        CloseLibrary (UtilityBase);
  109.       }
  110.      CloseLibrary (&IntuitionBase->LibNode);
  111.     }
  112.    CloseLibrary (&GfxBase->LibNode);
  113.   }
  114.  return FALSE;
  115. }
  116.  
  117. void MyBlankerLibFree(void)
  118. {
  119.  CloseLibrary (MathIeeeDoubTransBase);
  120.  CloseLibrary (MathIeeeDoubBasBase);
  121.  CloseLibrary (UtilityBase);
  122.  CloseLibrary (&IntuitionBase->LibNode);
  123.  CloseLibrary (&GfxBase->LibNode);
  124. }
  125.  
  126. struct BTDInfo *QueryMyBlanker(void)
  127. {
  128.  return &GalaxyInfo;
  129. }
  130.  
  131. #define MAX_GALAXIES        5
  132. #define MAX_HITITERATIONS    200
  133. #define MAX_IDELTAT        50
  134. /* These come originally from the Cluster-version */
  135. #define DEFAULT_GALAXIES    2
  136. #define DEFAULT_STARS        100
  137. #define DEFAULT_HITITERATIONS    7500
  138. #define DEFAULT_IDELTAT        200     /* 0.02 */
  139.  
  140. #define GALAKSIZE    3.0
  141. #define QCONS        0.001
  142.  
  143. #define COLORBASE4    4
  144.     /* Colors for stars start here */
  145. #define COLORSTEP4    4
  146.  
  147. typedef double Vector[3];
  148. typedef double Matrix[3][3];
  149.  
  150. typedef struct {
  151.     Vector pos, vel;
  152.     int px, py;
  153.     int color;
  154.     } Star;
  155.  
  156. typedef struct {
  157.     int mass;
  158.     int starscnt;
  159.     Star *stars;
  160.     int basecolor;
  161.     Vector pos, vel;
  162.     } Galaxy;
  163.  
  164. struct unistruct {
  165.  struct {
  166.  int left;                             /* x minimum */
  167.  int right;                            /* x maximum */
  168.  int top;                              /* y minimum */
  169.  int bottom;                           /* y maximum */
  170. } clip;                      
  171.     int galcol[MAX_GALAXIES];                 /* colors */
  172.     Matrix mat;                               /* Movement of stars(?) */
  173.     double scale;                             /* Scale */
  174.     int midx;                                 /* Middle of screen, x */
  175.     int midy;                                 /* Middle of screen, y */
  176.     double size;                              /* */
  177.     Vector diff;                              /* */
  178.     Galaxy galaxies[MAX_GALAXIES];            /* the Whole Universe */
  179.     double f_deltat;                          /* quality of calculation, calc'd by d_ideltat */
  180.     int f_galaxies;                           /* # galaxies */
  181.     int f_stars;                              /* # stars per galaxy */
  182.     int f_hititerations;                      /* # iterations before restart */
  183.     int step;                                 /* */
  184.     int init;                                 /* 1 -> re-initialize */
  185.   struct BTDDrawInfo *BTDDrawInfo;
  186.   int Colors;
  187.   LONG RandN,RandF,RandI;
  188. };
  189.  
  190. #define FindTagData(l,t,d) GetTagData((t),(d),(l))
  191.  
  192. void __regargs InitRandom(struct unistruct *RP,ULONG Instance)
  193.  
  194. {
  195.  ULONG Time[2];
  196.  
  197.  CurrentTime (&Time[0],&Time[1]);
  198.  RP->RandN=(LONG)Time[0];
  199.  
  200.  if (Time[1]<1024L) Time[1]|=1;
  201.  else Time[1]>>=10;
  202.  Time[1]^=Instance;
  203.  
  204.  RP->RandF=4*Time[1]+1;
  205.  RP->RandI=2*Time[1]+1;
  206. }
  207.  
  208. WORD __regargs Random(struct unistruct *GA,WORD Max)
  209.  
  210. {
  211.  GA->RandN=GA->RandF*GA->RandN+GA->RandI;
  212.  if (GA->RandN<0L) GA->RandN=-GA->RandN;
  213.  
  214.  return (WORD)(GA->RandN%Max);
  215. }
  216.  
  217. /* rainbow colors */
  218.  
  219. #define NUM_RAINBOW_COLORS 6
  220.  
  221. UBYTE RBRed[NUM_RAINBOW_COLORS+1]   = {0xFF,0xFF,0x00,0x00,0x00,0xFF,0xFF};
  222. UBYTE RBGreen[NUM_RAINBOW_COLORS+1] = {0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00};
  223. UBYTE RBBlue[NUM_RAINBOW_COLORS+1]  = {0x00,0x00,0x00,0xFF,0xFF,0xFF,0x00};
  224.  
  225. struct unistruct *InitMyBlanker(struct TagItem *TagList)
  226. {
  227.     struct unistruct *GA;
  228.     int i;
  229.     struct BTDDrawInfo *BTDDrawInfo;
  230.     ULONG *Error,Dummy,Instance,Index;
  231.     unsigned int time[2], a;
  232.  
  233.  if ((BTDDrawInfo=(struct BTDDrawInfo *)
  234.                    FindTagData(TagList,BTD_DrawInfo,NULL))==NULL) return NULL;
  235.  Error=(LONG *)FindTagData(TagList,BTD_Error,(ULONG)&Dummy);
  236.  if ((GA=AllocVec(sizeof(struct unistruct),MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  237.   {
  238.    *Error=BTDERR_Memory;
  239.    return NULL;
  240.   }
  241.  
  242. DEBUG_PRINT("Init\n");
  243.  
  244.  GA->BTDDrawInfo=BTDDrawInfo;
  245.  Instance=FindTagData(TagList,BTD_Instance,0L);
  246.  
  247.  InitRandom(GA,Instance);
  248.  timer(time);
  249.  a=time[0]^time[1];
  250.  srand48(a);
  251.  
  252.  GA->f_galaxies=FindTagData(TagList,GA_Galaxy,DEF_GALAXY);
  253.  GA->Colors=GA->f_galaxies*COLORSTEP4+COLORSTEP4;
  254.  
  255.     GA->f_stars          =  FindTagData(TagList,GA_Stars,DEF_STARS);
  256.     GA->f_hititerations  =  FindTagData(TagList,GA_Seconds,DEF_SECONDS);
  257.     GA->f_deltat         =  (double)FindTagData(TagList,GA_Deltat,DEF_DELTAT)/10000.0;
  258.  
  259.     GA->clip.left    = 0;
  260.     GA->clip.top     = 0;
  261.     GA->clip.right   = GA->BTDDrawInfo->BDI_Width-1;
  262.     GA->clip.bottom  = GA->BTDDrawInfo->BDI_Height-1;
  263.     GA->scale        = (double)(BTDDrawInfo->BDI_Width-1)/4.0;
  264.     GA->midx         = GA->clip.right/2;
  265.     GA->midy         = GA->clip.bottom/2;
  266.     GA->init         = 1;
  267.  
  268.     if(!GA->galaxies[0].stars){
  269.     
  270.     for (i=0; i<MAX_GALAXIES; ++i) {
  271.         GA->galaxies[i].starscnt=0;    /* 0 valid entries */
  272.         GA->galaxies[i].stars=(Star *)AllocVec(GA->f_stars*sizeof(Star),MEMF_PUBLIC|MEMF_CLEAR);
  273.     }
  274.     
  275.     }
  276.  
  277.  if (GA->Colors>NUM_RAINBOW_COLORS)
  278.   {
  279.    LONG ColNum,Col,RBCol;
  280.    UBYTE *Red,*Green,*Blue,*Changed;
  281.  
  282.    Red=BTDDrawInfo->BDI_Red;
  283.    Green=BTDDrawInfo->BDI_Green;
  284.    Blue=BTDDrawInfo->BDI_Blue;
  285.    Changed=BTDDrawInfo->BDI_Changed;
  286.    ColNum=GA->Colors/NUM_RAINBOW_COLORS+1L;
  287.    Index=0L;
  288.    for (RBCol=0L; RBCol<NUM_RAINBOW_COLORS; RBCol++)
  289.     {
  290.      if (RBCol==(GA->Colors%NUM_RAINBOW_COLORS)) ColNum--;
  291.  
  292.      for (Col=0L; Col<ColNum; Col++)
  293.       {
  294.        Red[BTDDrawInfo->BDI_Pens[Index]]=RBRed[RBCol]+((RBRed[RBCol+1]-RBRed[RBCol])*Col)/ColNum;
  295.        Green[BTDDrawInfo->BDI_Pens[Index]]=RBGreen[RBCol]+((RBGreen[RBCol+1]-RBGreen[RBCol])*Col)/ColNum;
  296.        Blue[BTDDrawInfo->BDI_Pens[Index]]=RBBlue[RBCol]+((RBBlue[RBCol+1]-RBBlue[RBCol])*Col)/ColNum;
  297.        Changed[BTDDrawInfo->BDI_Pens[Index++]]=TRUE;
  298.       }
  299.     }
  300.   }
  301.  else
  302.   for (Index=0L; Index<GA->Colors; Index++)
  303.    {
  304.     BTDDrawInfo->BDI_Red[BTDDrawInfo->BDI_Pens[Index]]=RBRed[Index];
  305.     BTDDrawInfo->BDI_Green[BTDDrawInfo->BDI_Pens[Index]]=RBGreen[Index];
  306.     BTDDrawInfo->BDI_Blue[BTDDrawInfo->BDI_Pens[Index]]=RBBlue[Index];
  307.     BTDDrawInfo->BDI_Changed[BTDDrawInfo->BDI_Pens[Index]]=TRUE;
  308.    }
  309.  
  310.  
  311. DEBUG_PRINT("Init Ready.\n");
  312.  
  313.  return GA;
  314.  
  315. }
  316. void EndMyBlanker(struct unistruct *GA)
  317.  
  318. {
  319.  int i;
  320.  if(GA->galaxies[0].stars)
  321.   for (i=0; i<MAX_GALAXIES; ++i) 
  322.    FreeVec(GA->galaxies[i].stars);
  323.  FreeVec (GA);
  324. }
  325.  
  326. UWORD PutChar[2] = {0x16C0,0x4E75};
  327.  
  328. /* dirty hack to avoid assembler part :-)
  329.  
  330.    16C0: move.b d0,(a3)+
  331.    4E75: rts
  332. */
  333.  
  334. void SPrintF(char *Buffer,char *FormatString,...)
  335.  
  336. {
  337.  RawDoFmt (FormatString,(APTR)((LONG *)&FormatString+1L),(void *)PutChar,Buffer);
  338. }
  339.  
  340. void AnimMyBlanker(struct unistruct *GA)
  341. {
  342.     double d;                                  /* tmp */
  343.     int i, j, k;                               /* more tmp */
  344.     int t1, t2, t3;
  345.  
  346. DEBUG_PRINT("Anim\n");
  347.  
  348.     if(GA->init){
  349.     double w1, w2;                     /* more tmp */
  350.     double v,w, h;                         /* yet more tmp */
  351.  
  352.     GA->init=0;
  353.     GA->step=0;
  354.     
  355.     for (i=0; i<MAX_GALAXIES; ++i){
  356.         GA->galcol[i]=i;
  357. DEBUG_PRINT("New Init\n");
  358.     }
  359.  
  360.    for (i=0; i<MAX_GALAXIES; ++i)
  361.      GA->galcol[i]=i;
  362.    for (i=0; i<MAX_GALAXIES; ++i) {
  363.      t1=(int)(Random(GA,MAX_GALAXIES));    /* t1=[0..MAX_GALAXIES-1] */
  364.      t2=(int)(Random(GA,MAX_GALAXIES));    /* t2=[0..MAX_GALAXIES-1] */
  365.  
  366.      t3=GA->galcol[t1];
  367.      GA->galcol[t1]=GA->galcol[t2];
  368.      GA->galcol[t2]=t3;
  369.      }
  370.  
  371.    for (i=0; i<GA->f_galaxies; ++i) {
  372.      GA->galaxies[i].basecolor=GA->galcol[i];
  373.  
  374.      GA->galaxies[i].starscnt=(int)(Random(GA,GA->f_stars/2))+GA->f_stars/2;
  375.  
  376.      w1=2.0*PI*drand48();
  377.      w2=2.0*PI*drand48();
  378.  
  379.      GA->mat[0][0]=         cos(w2);
  380.      GA->mat[0][1]=-sin(w1)*sin(w2);
  381.      GA->mat[0][2]= cos(w1)*sin(w2);
  382.      GA->mat[1][0]= 0.0;
  383.      GA->mat[1][1]= cos(w1);
  384.      GA->mat[1][2]= sin(w1);
  385.      GA->mat[2][0]=-        sin(w2);
  386.      GA->mat[2][1]=-sin(w1)*cos(w2);
  387.      GA->mat[2][2]= cos(w1)*cos(w2);
  388.  
  389.      GA->galaxies[i].vel[0]=Random(GA,2)-1.0;
  390.      GA->galaxies[i].vel[1]=Random(GA,2)-1.0;
  391.      GA->galaxies[i].vel[2]=Random(GA,2)-1.0;
  392.      GA->galaxies[i].pos[0]=-GA->galaxies[i].vel[0]*GA->f_deltat*GA->f_hititerations+drand48()-0.5;
  393.      GA->galaxies[i].pos[1]=-GA->galaxies[i].vel[1]*GA->f_deltat*GA->f_hititerations+drand48()-0.5;
  394.      GA->galaxies[i].pos[2]=-GA->galaxies[i].vel[2]*GA->f_deltat*GA->f_hititerations+drand48()-0.5;
  395.  
  396.      GA->galaxies[i].mass=(double)Random(GA,1000);
  397.  
  398.      t1=drand48();
  399.      GA->size=t1*t1*GALAKSIZE+0.1;
  400.  
  401.      for (j=0; j<GA->galaxies[i].starscnt; ++j) {
  402.     w=2.0*PI*drand48();
  403.     d=drand48()*GA->size;
  404.     h=drand48()*exp(-2.0*(d/GA->size))/5.0*GA->size;
  405.     if (drand48()<0.5) h=-h;
  406.     GA->galaxies[i].stars[j].pos[0]=GA->mat[0][0]*d*cos(w)+GA->mat[1][0]*d*sin(w)+GA->mat[2][0]*h+GA->galaxies[i].pos[0];
  407.     GA->galaxies[i].stars[j].pos[1]=GA->mat[0][1]*d*cos(w)+GA->mat[1][1]*d*sin(w)+GA->mat[2][1]*h+GA->galaxies[i].pos[1];
  408.     GA->galaxies[i].stars[j].pos[2]=GA->mat[0][2]*d*cos(w)+GA->mat[1][2]*d*sin(w)+GA->mat[2][2]*h+GA->galaxies[i].pos[2];
  409.  
  410.     v=sqrt(GA->galaxies[i].mass*QCONS/sqrt(d*d+h*h));
  411.     GA->galaxies[i].stars[j].vel[0]=-GA->mat[0][0]*v*sin(w)+GA->mat[1][0]*v*cos(w)+GA->galaxies[i].vel[0];
  412.     GA->galaxies[i].stars[j].vel[1]=-GA->mat[0][1]*v*sin(w)+GA->mat[1][1]*v*cos(w)+GA->galaxies[i].vel[1];
  413.     GA->galaxies[i].stars[j].vel[2]=-GA->mat[0][2]*v*sin(w)+GA->mat[1][2]*v*cos(w)+GA->galaxies[i].vel[2];
  414.  
  415.     GA->galaxies[i].stars[j].color=COLORBASE4+COLORSTEP4*GA->galaxies[i].basecolor+j%COLORSTEP4;
  416.         if(GA->galaxies[i].stars[j].color>GA->Colors) GA->galaxies[i].stars[j].color=GA->galaxies[i].stars[j].color%GA->Colors;
  417.  
  418.     GA->galaxies[i].stars[j].px=0;
  419.     GA->galaxies[i].stars[j].py=0;
  420.     }
  421.      }
  422.  
  423.      SetRast(GA->BTDDrawInfo->BDI_RPort, 0);
  424.     
  425.      }
  426.  
  427.      for (i=0; i<GA->f_galaxies; ++i) {
  428.     for (j=0; j<GA->galaxies[i].starscnt; ++j) {
  429.       for (k=0; k<GA->f_galaxies; ++k) {
  430.         GA->diff[0]=GA->galaxies[k].pos[0]-GA->galaxies[i].stars[j].pos[0];
  431.         GA->diff[1]=GA->galaxies[k].pos[1]-GA->galaxies[i].stars[j].pos[1];
  432.         GA->diff[2]=GA->galaxies[k].pos[2]-GA->galaxies[i].stars[j].pos[2];
  433.         d=GA->diff[0]*GA->diff[0]+GA->diff[1]*GA->diff[1]+GA->diff[2]*GA->diff[2];
  434.         d=GA->galaxies[k].mass/(d*sqrt(d))*GA->f_deltat*QCONS;
  435.         GA->diff[0]*=d;
  436.         GA->diff[1]*=d;
  437.         GA->diff[2]*=d;
  438.         GA->galaxies[i].stars[j].vel[0]+=GA->diff[0];
  439.         GA->galaxies[i].stars[j].vel[1]+=GA->diff[1];
  440.         GA->galaxies[i].stars[j].vel[2]+=GA->diff[2];
  441.         }
  442.       GA->galaxies[i].stars[j].pos[0]+=GA->galaxies[i].stars[j].vel[0]*GA->f_deltat;
  443.       GA->galaxies[i].stars[j].pos[1]+=GA->galaxies[i].stars[j].vel[1]*GA->f_deltat;
  444.       GA->galaxies[i].stars[j].pos[2]+=GA->galaxies[i].stars[j].vel[2]*GA->f_deltat;
  445.  
  446.       if (   GA->galaxies[i].stars[j].px>=GA->clip.left 
  447.               && GA->galaxies[i].stars[j].px<=GA->clip.right
  448.           && GA->galaxies[i].stars[j].py>=GA->clip.top 
  449.               && GA->galaxies[i].stars[j].py<=GA->clip.bottom)
  450.           {
  451.           SetAPen(GA->BTDDrawInfo->BDI_RPort,BTD_BgPen);
  452.           WritePixel(GA->BTDDrawInfo->BDI_RPort, GA->galaxies[i].stars[j].px, GA->galaxies[i].stars[j].py);
  453.           }
  454.  
  455.       GA->galaxies[i].stars[j].px=(int)(GA->galaxies[i].stars[j].pos[0]*GA->scale)+GA->midx;
  456.       GA->galaxies[i].stars[j].py=(int)(GA->galaxies[i].stars[j].pos[1]*GA->scale)+GA->midy;
  457.  
  458.       if (   GA->galaxies[i].stars[j].px>=GA->clip.left 
  459.               && GA->galaxies[i].stars[j].px<=GA->clip.right
  460.           && GA->galaxies[i].stars[j].py>=GA->clip.top 
  461.               && GA->galaxies[i].stars[j].py<=GA->clip.bottom)
  462.           {
  463.           SetAPen(GA->BTDDrawInfo->BDI_RPort,GA->BTDDrawInfo->BDI_Pens[GA->galaxies[i].stars[j].color]);
  464.           WritePixel(GA->BTDDrawInfo->BDI_RPort, GA->galaxies[i].stars[j].px, GA->galaxies[i].stars[j].py);
  465.           }
  466.  
  467.       }
  468.  
  469.     for (k=i+1; k<GA->f_galaxies; ++k) {
  470.       GA->diff[0]=GA->galaxies[k].pos[0]-GA->galaxies[i].pos[0];
  471.       GA->diff[1]=GA->galaxies[k].pos[1]-GA->galaxies[i].pos[1];
  472.       GA->diff[2]=GA->galaxies[k].pos[2]-GA->galaxies[i].pos[2];
  473.       d=GA->diff[0]*GA->diff[0]+GA->diff[1]*GA->diff[1]+GA->diff[2]*GA->diff[2];
  474.       d=GA->galaxies[i].mass*GA->galaxies[k].mass/(d*sqrt(d))*GA->f_deltat*QCONS;
  475.       GA->diff[0]*=d;
  476.       GA->diff[1]*=d;
  477.       GA->diff[2]*=d;
  478.       GA->galaxies[i].vel[0]+=GA->diff[0]/GA->galaxies[i].mass;
  479.       GA->galaxies[i].vel[1]+=GA->diff[1]/GA->galaxies[i].mass;
  480.       GA->galaxies[i].vel[2]+=GA->diff[2]/GA->galaxies[i].mass;
  481.       GA->galaxies[k].vel[0]-=GA->diff[0]/GA->galaxies[k].mass;
  482.       GA->galaxies[k].vel[1]-=GA->diff[1]/GA->galaxies[k].mass;
  483.       GA->galaxies[k].vel[2]-=GA->diff[2]/GA->galaxies[k].mass;
  484.       }
  485.     GA->galaxies[i].pos[0]+=GA->galaxies[i].vel[0]*GA->f_deltat;
  486.     GA->galaxies[i].pos[1]+=GA->galaxies[i].vel[1]*GA->f_deltat;
  487.     GA->galaxies[i].pos[2]+=GA->galaxies[i].vel[2]*GA->f_deltat;
  488.    }
  489.     GA->step++;
  490.     if(GA->step > GA->f_hititerations*4) GA->init=1;
  491. }
  492.  
  493.  
  494. ULONG PenCountMyBlanker(struct TagItem *TagList)
  495.  
  496. {
  497.  return GetTagData(GA_Galaxy,DEF_GALAXY,TagList)*COLORSTEP4+COLORSTEP4;
  498. }
  499.